package cn.edu.seu.ssny.dao;

import cn.edu.seu.ssny.dao.support.IBaseDao;
import cn.edu.seu.ssny.entity.Device;
import cn.edu.seu.ssny.entity.DeviceData;
import cn.edu.seu.ssny.entity.Project;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;
import java.util.Optional;

@Repository
public interface IDeviceDataDao extends IBaseDao<DeviceData, Integer> {
    //@Query(value = "select id, create_time, data, device_id, is_modified ,modified_data, modified_time from tb_device_data  where device_id=? order by create_time desc limit 1", nativeQuery = true)
    Optional<DeviceData> findFirstByDeviceOrderByCreateTimeDesc(Device device);

    Optional<DeviceData> findFirstByDeviceAndCreateTimeGreaterThanEqualOrderByCreateTimeAsc(Device device, Date createTime);

    Optional<DeviceData> findFirstByDeviceAndCreateTimeLessThanEqualOrderByCreateTimeDesc(Device device, Date createTime);

    Optional<DeviceData> findFirstByDeviceAndCreateTimeBetweenOrderByCreateTimeAsc(Device device, Date start, Date end);

    List<DeviceData> findAllByDeviceAndCreateTimeBetweenOrderByCreateTimeAsc(Device device, Date start, Date end);
}
